package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
)

func main() {
	// 此处填写您在控制台-应用管理-创建应用后获取的AK
	ak := "FwHcrT3Wrfyi6LE67aGHpQGfV0JHdoCR"

	// 服务地址
	host := "https://api.map.baidu.com"

	// 接口地址
	uri := "/directionlite/v1/driving"

	// 设置请求参数
	params := url.Values{
		"origin":      []string{"40.01116,116.339303"},
		"destination": []string{"39.936404,116.452562"},
		"ak":          []string{ak},
	}

	// 发起请求
	request, err := url.Parse(host + uri + "?" + params.Encode())
	if nil != err {
		fmt.Printf("host error: %v", err)
		return
	}

	resp, err1 := http.Get(request.String())
	fmt.Printf("url: %s\n", request.String())
	defer resp.Body.Close()
	if err1 != nil {
		fmt.Printf("request error: %v", err1)
		return
	}
	body, err2 := ioutil.ReadAll(resp.Body)
	if err2 != nil {
		fmt.Printf("response error: %v", err2)
	}

	fmt.Println(string(body))

	return
}
